﻿using DeviceCommons.DataHandling;
using DeviceCommons.DeviceMessages.Abstractions;
using DeviceCommons.DeviceMessages.Models.V1;
using System.Buffers;

namespace DeviceCommons.DeviceMessages.Serialization.V2.Serializers
{
    public class DeviceMessageInfoReadingSerializer : AbstractMessageSerializer<IDeviceMessageInfoReading>, IDeviceMessageInfoReadingSerializer
    {
        public DeviceMessageInfoReadingSerializer() : base(new DeviceMessageInfoReading())
        {
        }

        public override void Serializer(ArrayBufferWriter<byte> writer, IDeviceMessageInfoReading message)
        {
            ArgumentNullException.ThrowIfNull(message);
            ArgumentNullException.ThrowIfNull(message.State);
            writer.Write(message.Offset);
            DeviceMessageSerializerProvider.InfoReadingStatesV2Ser.Serializer(writer, message.State);
        }
    }
}
